<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('选择工具')" />
</head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
				    <input type="hidden" id="status" name="status"  value="1">
					<div class="select-list">
						<ul>
							<li>
								工具类型： <select class="selectpicker" id="toolsTypeId" name="toolsTypeId"  data-live-search="true" data-size="10" >
						  			  </select>
	  			  			</li>
							<li>
								关键字：<input type="text" placeholder='库存编号/工具名称/工具类型/工具厂家/规格型号/工具柜/RFID'  name="keyword" id="keyword" />
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "toolLedger/directStorage";
		var voltage_level = [[${@dict.getType('voltage_level')}]];	
		$(function() {
			var options = {
		        url: prefix + "/list",
		        queryParams: queryParams,
		        showSearch: false,
		        striped: true,
		        showRefresh: false,
		        showToggle: false,
		        pageList: [100,200,300],      
		        showColumns: false,
		        clickToSelect: true,
		        rememberSelected: true,
		     	onLoadSuccess:function(data){
					signByKeyword($("#keyword").val(), [3,5,6,7,9,10]);// 标记关键字
					$.table.onLoadSuccess(data);
		        },
		        columns: [{
	        	  	field: 'selectItem', 
	                radio: true
		        },
	            {
	                title: 'id',
	                field: 'id',
	                visible: false
	            },
	            {
	                title: 'name',
	                field: 'name',
	                visible: false
	            },
	            {
	                title: 'modelName',
	                field: 'modelName',
	                visible: false
	            },
	            {
	                title: "序号",
	                formatter: function (value, row, index) {
	                    return $.table.serialNumber(index);
	                }
	            },
	            {
	                field: 'useCode',
	                title: '<span style="color:red" >*</span>试样编号',
	                sortable: true,
	                formatter: function (value, item, index) {
	                	return $.table.tooltip(value);
	                }
	            },
	            {
	            	field: 'toolName',
	            	title: '<span style="color:red" >*</span>工具名称',
	            	sortable: true,
	            	formatter: function(value, row, index) {
	            		return $.table.tooltip(value);
	            	}
	            },
	            {
	            	field: 'name',
	            	title: '<span style="color:red" >*</span>工具类型',
	            	sortable: true,
	            	formatter: function(value, row, index) {
	            		return $.table.tooltip(value);
	            	}
	            },
	            {
	                field: 'factoryName',
	                title: '<span style="color:red" >*</span>工具厂家',
	                sortable: true,
	                formatter: function(value, row, index) {
	                	return $.table.tooltip(value);
	                }
	            },
	            {
	                field: 'modelName',
	                title: '<span style="color:red" >*</span>规格型号',
	                sortable: true,
	                formatter: function(value, row, index) {
	                	return $.table.tooltip(value);
	                }
	            },
	            {
	                field: 'elecLevelId',
	                title: '电压等级',
	                sortable: true,
	            	formatter: function (value, row, index) {
	            		return $.table.selectDict(voltage_level, value);
	            	}
	            },
	            {
	                field: 'testDate',
	                title: '试验日期',
	                sortable: true,
	                formatter: function (value, row, index) {
	                    return formatUndefine(value).substring(0, 10);
	                }
	            },
	            {
	                field: 'buyDate',
	                title: '生产日期',
	                sortable: true,
	                formatter: function (value, row, index) {
	                    return formatUndefine(value).substring(0, 10);
	                }
	            }
	           ]
		    };
		    $.table.init(options);
		    initParentType();
		    initFactoryType();
		});
		
		function queryParams(params) {
			return {
				status  :"1",
				pageSize:       params.limit,
    			pageNum:        params.offset / params.limit + 1,
    			searchValue:    params.search,
    			orderByColumn:  params.sort,
    			isAsc:          params.order
			};
		}
		
		/**
		 * 初始化工具类型
		 */
		function initParentType() {

		    $.ajax({
		        cache: true,
		        type: "POST",
		        url: ctx + "basicData/toolsType/initParentType",
		        async: false,
		        error: function (request) {
		            $.modal.alertError("系统错误");
		        },
		        success: function (data) {
		            $('#toolsTypeId').empty();
		            var storeHtml = "<option value=''>显示全部</option>";
		            $.each(data, function (index, row) {
		                storeHtml += "<option value=\"" + row.id + "\"  >" + row.name + "</option>"
		            })
		            $("#toolsTypeId").html(storeHtml);
		            $("#toolsTypeId").selectpicker('refresh');
		        }
		    });
		}

		/**
		 * 初始化工具厂家
		 */
		function initFactoryType() {

		    $.ajax({
		        cache: true,
		        type: "POST",
		        url: ctx + "basicData/toolsFactory/initFactory",
		        async: false,
		        error: function (request) {
		            $.modal.alertError("系统错误");
		        },
		        success: function (data) {
		            $('#factoryId').empty();
		            var storeHtml = "<option value=''>显示全部</option>";
		            $.each(data, function (index, row) {
		                storeHtml += "<option value=\"" + row.id + "\"  >" + row.factoryName + "</option>"
		            })
		            $("#factoryId").html(storeHtml);
		            $("#factoryId").selectpicker('refresh');
		        }
		    });

		}
	</script>
</body>
</html>